package com.lagou.rocket.controller;

import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("/send/{message}")
    public String sendMq(@PathVariable String message) {
        if (StringUtils.isNoneEmpty(message)) {
            rocketMQTemplate.convertAndSend("topic_snapped", message);
            return message;
        }
        return "false";
    }

    @RequestMapping("/send2/{message}")
    public String sendMq2(@PathVariable String message) {
        if (StringUtils.isNoneEmpty(message)) {
            rocketMQTemplate.syncSend("topic_order_over", MessageBuilder.withPayload(message).build(), 100, 6);

            return message;
        }
        return "false";
    }
}
